/**
 * 
 * Opened Touchable RIA Framework - A Web RIA Javascript Framework
 * 
 * Copyright (c) 2012
 * Dual licensed under the MIT or GPL v2 licenses.
 * 
 * @author  CuTe_CuBe
 * @version $Id: canvas.js 6 2012-03-10 12:51:49Z cc.hgfeng@gmail.com $
 */

/**
 * OTR.Graph.Canvas
 * HTML5 canvas 绘图接口实现
 * 
 * @class OTR.Graph.Canvas
 * @constructor
 * @param object params
 */
OTR.Graph.Canvas = OTR.extend(OTR.Graph.Adapter, {
    /**
     * 初始化绘图对象
     * 
     * @param object params
     */
    init: function(config) {
        if (!OTR.Util.isObject(config)) {
            //throw 'Invalid params';
        }
        
        this._setType('Canvas');
        this._cfgs = {
            width: 100,
            height: 100,
            doc: document
        };
        
        for (var k in config) {
            if (undefined !== this._cfgs[k]) {
                this._cfgs[k] = config[k];
            }
        }
        
        var canvas = this._cfgs.doc.createElement('canvas');
        canvas.width  = this._cfgs.width;
        canvas.height = this._cfgs.height;
        
        this._canvas  = canvas;
    },

    /**
     * 绘制文字
     * 
     * @param string text 
     * @param mixed  size
     * @param int    x
     * @param int    y
     * @param string font
     * @return OTR.Graph.Adapter
     */
    drawText: function(text, size, x, y, font) {},
    
    /**
     * 插入图片
     * 
     * @param string src
     * @param int   width
     * @param int   height
     * @param int   x
     * @param int   y
     * @return OTR.Graph.Adapter
     */
    drawImage: function(src, width, height, x, y) {},
    
    /**
     * 获取绘图上下文
     * 
     * @return context
     */
    getContext: function(type) {
        if (undefined == type) {
            type = '2d';
        }
        
        if (undefined == this._context) {
            this._context = this._canvas.getContext(type);
            this._context.lineJoin = 'round';
        }

        return this._context;
    }
});